import { mapState, useStore } from 'vuex';
import { computed } from 'vue';

export default function useState(mapper) {
  // 拿到store独享
  const store = useStore()

  // const storeStateFns = mapState(['counter', 'name']);
  const storeStateFns = mapState(mapper);
  const storeState = {};

  Object.keys(storeStateFns).forEach(fnKey => {
    const fn = storeStateFns[fnKey].bind({ $store: store });
    storeState[fnKey] = computed(fn)
  });

  return storeState;
}